<style lang="stylus" scoped>
main
  padding 2rem
  height 100%
  align-items center
  justify-content center

  .logo
    background url('!/svg/logo.svg') 0 0 / contain no-repeat
    width 150px
    height 58px
    margin-bottom 32px

    &+p
      font-size 18px
      margin-bottom 20px

  p
    a
      color #FF9E40
      border-radius 3px
      border 2px solid @color
      padding 6px 12px
      font-weight bold
      margin 8px 0 12px
      display block

  .tip
    align-items center
    flex-direction column

    p
      font-size 14px
      margin-bottom 6px
</style>

<template lang="pug">
main
  x(@click="x")
  .logo
  p V{{ now }}
    span(v-if="latest === 0") (当前版本是最新的)
  .tip
    template(v-if="latest")
      p 发现新版本 {{ latest }}
      p
        a(@click="relaunch" v-if="updated") 更新成功，点此重启应用
        span(v-else) 更新中
      p(v-html="updated" v-if="updated")
    p(v-else) 已是最新版本
</template>

<script lang="coffee">
import x from '~/vue/x.vue'
import ipc from '~/lib/ipc.coffee'
import ON from '~/lib/broadcast/on.coffee'
import broadcast from '~/lib/broadcast.coffee'
import Md from '~/lib/md.coffee'
import bin_ver from '~/lib/bin_ver.coffee'
import '~/styl/win/border.styl'

{auto_update} = ipc

export default {
components:{
x
}
setup:=>
  now = shallowRef()
  latest = shallowRef()
  updated = shallowRef()

  onMounted =>
    now.value = await auto_update.ver_now()
    if latest.value = bin_ver await auto_update.update_check()
      [bin,md] = await auto_update.update()
      latest.value = bin_ver bin
      updated.value = Md '更新日志:\n\n'+md
    return
  {
    now
    latest
    updated
    x:=>
      auto_update.x()
    relaunch:=>
      auto_update.relaunch()
      return
  }
}
</script>
